]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell/app: Fix small memory leak in get_pids()
authorSebastian Keller <skeller@gnome.org>
Wed, 6 Jul 2022 17:34:23 +0000 (19:34 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 6 Jul 2022 18:13:46 +0000 (18:13 +0000)
The iterator was pointing to NULL when going out of scope, leading to
autofree not clearing the list.

==300183== 32 bytes in 2 blocks are definitely lost in loss record 14,798 of 38,939
==300183==    at 0x484586F: malloc (vg_replace_malloc.c:381)
==300183==    by 0x4D7D980: g_malloc (gmem.c:127)
==300183==    by 0x4D95AB3: g_slice_alloc (gslice.c:1074)
==300183==    by 0x4D96D96: g_slist_prepend (gslist.c:282)
==300183==    by 0x487854F: shell_app_get_windows (shell-app.c:794)
==300183==    by 0x48791A1: shell_app_get_pids (shell-app.c:1201)
==300183==    by 0x488B293: shell_window_tracker_get_app_from_pid (shell-window-tracker.c:702)
==300183==    by 0x488B632: get_app_from_window_pid (shell-window-tracker.c:370)
==300183==    by 0x488B632: get_app_for_window (shell-window-tracker.c:436)
==300183==    by 0x488B632: track_window (shell-window-tracker.c:549)
==300183==    by 0x4CDBB75: g_cclosure_marshal_VOID__OBJECTv (gmarshal.c:1910)
==300183==    by 0x4CD8BE9: _g_closure_invoke_va (gclosure.c:893)
==300183==    by 0x4CF2A28: g_signal_emit_valist (gsignal.c:3406)
==300183==    by 0x4CF2C2C: g_signal_emit (gsignal.c:3553)

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2367>

src/shell-app.c

index 96fe31bff33365001fb854ec9f2e941d73a2af2a..5c38a9c8d84b813d3284ae2667251d2bf7c29846 100644 (file)
@@ -1195,10 +1195,12 @@ GSList *
 shell_app_get_pids (ShellApp *app)
 {
   GSList *result;
-  g_autoptr (GSList) iter = NULL;
+  g_autoptr (GSList) windows = NULL;
+  GSList *iter;
 
   result = NULL;
-  for (iter = shell_app_get_windows (app); iter; iter = iter->next)
+  windows = shell_app_get_windows (app);
+  for (iter = windows; iter; iter = iter->next)
     {
       MetaWindow *window = iter->data;
       pid_t pid = meta_window_get_pid (window);